package com.future.prototype;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2021/11/16 14:20
 */
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {
        User user = new User();
        user.setId(1);
        user.setAddress("广西");
        user.setName("wrb");
        System.out.println(user);
        User clone = user.clone();
        System.out.println();
        System.out.println(clone);
        System.out.println(user == clone);
        System.out.println("===================对象里有对象时===================");
        Student student = new Student(1, "wrb");

        Teacher teacher = new Teacher();
        teacher.setUser(user);
        teacher.setId(666);
        teacher.setName("欧老师");
        teacher.setStudents(student);
        System.out.println(teacher);
        Teacher teacherClone = teacher.clone();
        System.out.println(teacherClone);
        System.out.println("克隆后是否还是同一个对象：" + (teacher == teacherClone) + "");
        // 修改student
        student.setId(888);
        student.setName("韦俊毅");
        user.setName("哈哈哈");
        user.setId(999);
        System.out.println("修改没有实现cloneable接口的对象Student后");
        System.out.println(teacher);
        System.out.println(teacherClone);
        System.out.println("student对象是否相等：" + (teacher.getStudents() == teacherClone.getStudents()) + "");
        System.out.println("user对象是否相等：" + (teacher.getUser() == teacherClone.getUser()) + "");
        System.out.println("修改实现cloneable接口的对象User后");
    }
}
